package com.qumitech.visualnovel.component.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @Auther: bke
 * @Date: 2018/8/21 12:16
 * @Description:
 */
@Component
@Order(1)
public class BeanFactoryUtil implements ApplicationContextAware {
    private static ApplicationContext applicationContext = null;



    @Override

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

        if (BeanFactoryUtil.applicationContext == null) {

            BeanFactoryUtil.applicationContext = applicationContext;

        }
    }

    public static ApplicationContext getApplicationContext() {

        return applicationContext;

    }

    public static Object getBean(String name){

        return getApplicationContext().getBean(name);

    }
}
